<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input searchVal" placeholder="请输入搜索的内容" />
                </div>
                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>
        </form>
    </blockquote>
    <table id="custLostList" lay-filter="custLostList"></table>
    <!--操作-->
    <script type="text/html" id="custLostListBar">
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="delete">返回正常状态</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="toLost">进入流失管理</a>
    </script>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl'],function() {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        //新闻列表
        var tableIns = table.render({
            elem: '#custLostList',
            url: 'custWillLosts',
            cellMinWidth: 95,
            page: true,//分页
            height: "full-125",
            limit: 5,
            limits: [5, 10, 15, 20, 25, 30],
            id: "custLostListTable",
            cols: [[
                {type: "checkbox", fixed: "left"},//复选框
                {field: 'custNo', title: '编号', align: "center"},
                {field: 'custName', title: '客户', align: "center"},
                {
                    field: 'latelyOrder', title: '订单编号',  align: "center", templet: function (row) {
                        return row.latelyOrder.ordeNo;
                    }
                },
                {
                    field: 'latelyOrder', title: '最近的订单日期', align: "center", templet: function (row) {
                        return row.latelyOrder.ordeDate;
                    }
                },
                {title: '操作', width:250, templet:'#custLostListBar',fixed:"right",align:"center"}
            ]]
        });

        $(".search_btn").on("click",function(){
            table.reload("custLostListTable",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    custName:$(".searchVal").val()
                }
            })
        });

        table.on("tool(custLostList)",function (obj) {
            //获取当前行的数据
            var data=obj.data;
            switch (obj.event){
                case 'delete':
                    delete1(data);
                    break;
                case 'toLost':
                    toLost(data);
                    break;
            }
        });
        //返回正常状态，改变custFlag=0
        function delete1(data){
            var orderCustNo=data.custNo
            $.ajax({
                url:"/updateCustFlag",
                data:{orderCustNo:orderCustNo},
                type:"GET",
                dataType:"json",
                success:function (res) {
                    if(res.code==2010){
                        layer.msg(res.msg)
                        tableIns.reload();//重新刷新表格
                    }else{
                        layer.msg(res.msg);
                    }
                }
            })
        }
        //流失管理添加数据
        function toLost(data){
            var orderCustNo=data.custNo
                $.ajax({
                url:"/addCustLosts",
                data:{orderCustNo:orderCustNo},
                type:"GET",
                dataType:"json",
                success:function (res) {
                    if(res.code==2011){
                        layer.msg(res.msg)
                        tableIns.reload();//重新刷新表格
                    }else{
                        layer.msg(res.msg);
                    }
                }
            })
        }
    })
</script>
</body>
</html>